var baseUrl = 'http://192.168.1.102/'; //狗哥本地
// var baseUrl = 'http://101.132.163.6:8080/nxmu-hire-web/'; //测试
var urls = {
    getCollege: baseUrl+'enum/college',//获取学院枚举
    getResearch: baseUrl+'enum/researchByCollegeId',//获取教研室枚举
    loginReg: baseUrl+'user/login',//登录接口
    logout: baseUrl+'user/logout',//退出登录

    /*-------人事处------------------------------------------*/
    addTeacher: baseUrl+'teacher/save',//添加教师
    teachList: baseUrl+'teacher/findTeacherByCondition',//教师列表-人事处查看教师列表
    editTeacherInfo: baseUrl+'teacher/modifyTeacher',//修改教师信息
    deleteTeacher: baseUrl+'teacher/deleteById',//删除教师
    addTeachPost: baseUrl+'post/addPost',//添加教学岗位
    teachPostList: baseUrl+'post/findPostListByPage',//查询教学岗位列表
    editPostNum: baseUrl+'post/modifyPostCount',//修改岗位数量
    addGradeCoefficient: baseUrl+'gradeCoefficient/addGradeCoefficient',//修改评分系数
    checkCoefficient:baseUrl+'gradeCoefficient/findGradeCoefficient',//查询评分系数

    /*---------教学办------------------------------------------*/
    addWorks: baseUrl+'workload/addWorkload',//添加工作量
    worksList: baseUrl+'workload/findAllWorkload',//工作量列表
    editWorks: baseUrl+'workload/modifyWorkload',//修改基本教学工作量

    /*--------教师-----------------------------------------------------*/
    modifyPassword : baseUrl + 'user/modifyPassword',//修改密码
    getTeaInfo: baseUrl+'teacher/findTeacherByUserId', //获取教师个人信息
    applyApy: baseUrl+'apply/apply',//申报
};

var requests = {
    postReq: function (url,param,succFun,errorFun) {
        $("#loading").show();
        $("body").css('overflow','hidden');
        $.ajax({
            type: 'POST',
            url: url,
            data: param,
            dataType: 'json',
            contentType: 'application/json;charset=utf-8',
            xhrFields: {
                withCredentials: true
            },
            success: function (data) {
                $("#loading").hide();
                $("body").css('overflow','auto');
                succFun(data);
            },
            error: function (data) {
                $("#loading").hide();
                $("body").css('overflow','auto');
                if(errorFun){
                    errorFun(data);
                }else{
                    console.log(data);
                    showTip('服务器请求错误');
                }
            }
        })
    },
    getReq: function (url,param,succFun,errorFun) {
        $("#loading").show();
        $("body").css('overflow','hidden');
        $.ajax({
            type: 'GET',
            url: url,
            data: param,
            dataType: 'json',
            contentType: 'application/json;charset=utf-8',
            xhrFields: {
                withCredentials: true
            },
            success: function (data) {
                $("#loading").hide();
                $("body").css('overflow','auto');
                succFun(data);
            },
            error: function (data) {
                $("#loading").hide();
                $("body").css('overflow','auto');
                if(errorFun){
                    errorFun(data);
                }else{
                    console.log(data);
                    showTip('服务器请求错误');
                }
            }
        })
    }
};

$(function () {
    $("body").append(
        '<div id="tipBox">\n' +
        '<div>' +
        '<div class="tipText">教师添加成功</div>\n' +
        '<div class="okBtn">我知道了</div>\n' +
        '</div>' +
        '</div>' +
        '<div id="loading">\n' +
        '<img src="../images/loading.gif" alt="加载中">' +
        '</div>'
    );
});

//性别
var commonGender = {
    'FEMALE': '女',
    'MALE': '男'
}
//学历
var commonEducation = {
    "DOCTOR": "博士",
    "MASTER": "硕士",
    "BACHELOR": "学士"
}
//角色
var commonRole = {
    "TEACHER": "教师",
    "RESEARCH": "教研室",
    "OFFICE": "教学办",
    "HR": "人事处"
}
//职称
var commonTitle = {
    "AP": "教授",
    "PROFESSOR": "副教授",
    "LECTURER": "讲师",
    "ASSISTANT": "助教"
}
//学年及学期JSON配置
var termYear = {
    'N18':{
        'year':'2018',
        'term':'N',
        'name':'2018-2019学年春季学期'
    },
    'P18':{
        'year':'2018',
        'term':'P',
        'name':'2018-2019学年秋季学期'
    },
    'N17':{
        'year':'2017',
        'term':'N',
        'name':'2017-2018学年春季学期'
    },
    'P17':{
        'year':'2017',
        'term':'P',
        'name':'2017-2018学年秋季学期'
    },
    'N16':{
        'year':'2016',
        'term':'N',
        'name':'2016-2017学年春季学期'
    },
    'P16':{
        'year':'2016',
        'term':'P',
        'name':'2016-2017学年秋季学期'
    },
    'N15':{
        'year':'2015',
        'term':'N',
        'name':'2015-2016学年春季学期'
    },
    'P15':{
        'year':'2015',
        'term':'P',
        'name':'2015-2016学年秋季学期'
    },
    'N14':{
        'year':'2014',
        'term':'N',
        'name':'2014-2015学年春季学期'
    },
    'P14':{
        'year':'2014',
        'term':'P',
        'name':'2014-2015学年秋季学期'
    }
}

//标识左侧边栏
function menuActive(father,son) {
    $(".menuson").hide();
    $(".menuson").eq(father).show();
    $(".menuson").eq(father).children('li').eq(son).addClass('active');
}
//返回学期字符串
function compTermYear(y,t) {
    for(var key in termYear){
        if(termYear[key].year == y && termYear[key].term == t){
            return termYear[key].name;
        }
    }
}
//返回时间字符串
function compTime(time) {
    var timeObj = new Date(time);
    var month = timeObj.getMonth()+1;
    var timeStr = timeObj.getFullYear()+'年'+month+'月'+timeObj.getDate()+'日';
    return timeStr;
}

//判断分页按钮是否可用
function pageBtnState(pageNum,hasNext,hasPrev) {
    curPageNum = pageNum;
    if(hasNext == false){
        $("#nextPage").addClass('unClick');
    }else{
        $("#nextPage").removeClass('unClick');
    }
    if(hasPrev == false){
        $("#prevPage").addClass('unClick');
    }else{
        $("#prevPage").removeClass('unClick');
    }
}

//提示框
function showTip(txt,fun) {
    $("#tipBox .tipText").html(txt);
    $("#tipBox").show();
    $("body").css('overflow','hidden');
    $("html,body").animate({scrollTop:0},100);
    $("#tipBox .okBtn").click(function(){
        if(fun){
            fun();
        }
        $("#tipBox").hide();
        $("#tipBox .tipText").html('');
        $("body").css('overflow','auto');

    });
}

//初始化学年学期下拉列表
function initTermSel(id){
    var optList = '';
    for(var key in termYear){
        optList += '<option value="'+key+'">'+termYear[key].name+'</option>'
    }
    $("#"+id).append(optList);
}

$("#close_editBox").click(function () {
    $("#editBox").hide();
})